package timer;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author ml
 * @create 2017-11-06--15:32
 */
public class TimerDemo {

    public static void main(String[] args) {
        Timer timer=new Timer();
        Calendar calendar=Calendar.getInstance();
        //timer.scheduleAtFixedRate(new MyTask(),calendar.getTime(),1000);
        timer.schedule(new MyTask(),calendar.getTime(),6000);
    }

}

class MyTask extends TimerTask {

    @Override
    public void run() {

        System.out.println("execute time start is :" +
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.scheduledExecutionTime())+
        Thread.currentThread().getName());

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
